#include <stdio.h>
#include <stdlib.h>

#include "array.h"

Array array_create(int init_size) {
	Array a;
	a.array = (int*)malloc(sizeof(int) * init_size);
	a.size = init_size;
	return a;
}

void array_free(Array * a) {
	free(a->array);
	a->array = NULL;
	a->size = 0;
}
int array_size(const Array* a) {
	return a->size;
}
int* array_get(Array* a,int Index) {
	return &(a->array[Index]);
}
void array_set(Array* a, int Index, int val)//修改某个元素的值 
{
	(a->array)[Index] = val;
}

void array_inflate(Array* a, int more_size)   //核心：让数组变长的函数 
{
	int i;
	int* p = (int*)malloc(sizeof(int) * ((a->size) + more_size));
	for (i = 0; i < a->size; i++)
	{
		p[i] = (a->array)[i];
	}
	free(a->array);
	a->array = p;
	a->size += more_size;
}